<template>
    <div>
        <Form :label-width="130" inline>
            <Form-item label="批次号：">
                <Select v-model="queryParam.tacp0016" style="width:200px" clearable>
                    <Option v-for="item in tacp0016List" :value="item" :key="item">{{item}}</Option>
                </Select>
            </Form-item>
            <Form-item label="数据状态:">
                <Select v-model="queryParam.tacp0014" style="width:200px" clearable>
                    <Option value="0" key="0">待确认数据</Option>
                    <Option value="1" key="1">确认数据</Option>
                    <Option value="2" key="2">历史数据</Option>
                </Select>
            </Form-item>

            <Form-item label="属地区划:">
                <area-linkage :areaCode.sync="queryParam.tacp0001" id="area"></area-linkage>
            </Form-item>

            <Form-item label="经办人姓名:">
                <Input v-model="queryParam.tacp0003" placeholder="请输入经办人姓名" style="width:200px"/>
            </Form-item>

            <Form-item label="经办人身份证号码:">
                <Input v-model="queryParam.tacp0004" placeholder="请输入经办人身份证号码" style="width:200px"/>
            </Form-item>

            <Form-item label="亲属姓名:">
                <Input v-model="queryParam.tacp0011" placeholder="请输入亲属姓名" style="width:200px"/>
            </Form-item>

            <Form-item label="亲属身份证号码:">
                <Input v-model="queryParam.tacp0013" placeholder="请输入亲属身份证号码" style="width:200px"/>
            </Form-item>
            <Row class="button_row">
                <span style="float: left;">
                     <Upload action="/api/ac/subsistence/Ss02100Service/importExcel"
                             style="display: inline-block;margin-left: 20px"
                             :on-success="onSuccess" :before-upload="beforeUpload" :on-error="onError"
                             name="files">
                <Button type="primary" icon="ios-cloud-upload-outline">导入</Button>
                     </Upload>
                      <Button type="primary" icon="ios-cloud-download-outline" @click="exportTemplate"
                              class="button_item_left">
                       下载模版
                     </Button>
                </span>
                <span style="float: right;">
                  <Button type="primary" @click="searchQuery">查询</Button>
                 <Button type="primary" class="button_item_left" @click="searchReset">重置</Button>
                 <template v-if="determine">
                 <Button type="primary" class="button_item_left" @click="clickDetermine">确认</Button>
                 </template>
                </span>
            </Row>
        </Form>
        <div class="table_div">
            <Table :columns="columns" :data="tableData" :loading="Loading" class="auto-column-size-table">
                <template slot-scope="{row}" slot="action">
                    <Button type="success" size="small" style="margin-right: 5px" @click="handleDetail(row)">详情
                    </Button>
                </template>
            </Table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>
        <ss02100-modal ref="modalForm"/>
    </div>

</template>
<script>
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import {getAction, postAction} from '@/api/request'
    import ss02100Modal from './modules/ss02100Modal'

    export default {
        mixins: [CommonMixin],
        components: {
            ss02100Modal
        },
        data() {
            return {
                columns: [
                    {
                        title: '批次号',
                        key: 'tacp0016',
                        align: "center"
                    },
                    {
                        title: '属地区划',
                        key: 'tacp0002',
                        align: "center",
                    },

                    {
                        title: '经办人姓名',
                        key: 'tacp0003',
                        align: "center"
                    },
                    {
                        title: '经办人身份证号码',
                        key: 'tacp0004',
                        align: "center"
                    },
                    {
                        title: '亲属姓名',
                        key: 'tacp0011',
                        align: "center"

                    },

                    {
                        title: '亲属身份证号码',
                        key: 'tacp0013',
                        align: "center"
                    },
                    {
                        title: '亲属关系',
                        key: 'tacp0006',
                        align: "center"
                    },
                    {
                        title: '数据状态',
                        key: 'tacp0014',
                        align: "center",
                        render: (h, params) => {
                            if (params.row.tacp0014 == '0') {
                                return h('span', '待确认数据');
                            } else if (params.row.tacp0014 == '1') {
                                return h('span', '确认数据');
                            } else if (params.row.tacp0014 == '2') {
                                return h('span', '历史数据');
                            }
                        }
                    },
                    {
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        slot: 'action',
                    }
                ],
                ss02100: {},
                queryParam: {},
                tacp0016List: {},
                Loading: true,
                determine: false,
                url: {
                    list: "/api/ac/subsistence/Ss02100Service/page",
                    exportTemplate: "/api/ac/subsistence/Ss02100Service/exportTemplate",
                    exportExcel: "/api/ac/subsistence/Ss02100Service/exportExcel",
                    getTacp0016List: "/api/ac/subsistence/Ss02100Service/getTacp0016List",
                    isCanDetermine: "/api/ac/subsistence/Ss02100Service/isCanDetermine",
                    determine: "/api/ac/subsistence/Ss02100Service/insertDetermine"
                },
                exportTemplateFileName: "经办人及近亲属维护模版",
                exportFileName: "经办人及近亲属维护信息表",
            }
        },
        methods: {

            //文件上传
            beforeUpload() {
                this.Loading = true;
                return true;
            },

            //获取批次列表
            getTacp0016List() {
                getAction(this.url.getTacp0016List, {}).then((res) => {
                    this.tacp0016List = res.data.data;
                })
            },
            //
            isCanDetermine() {
                getAction(this.url.isCanDetermine, {}).then((res) => {
                    this.determine = res.data.data;
                })
            },
            clickDetermine(row) {
                var that = this;
                this.$Modal.confirm({
                    title: '数据确认？',
                    onOk: () => {
                        var tacp0016 = that.queryParam.tacp0016;
                        if (tacp0016) {
                            postAction(this.url.determine, {tacp0016: tacp0016}).then((res) => {
                                if (res.data.errcode != 0) {
                                    this.$Message.error(res.data.errmsg);
                                } else {
                                    this.$Message.success("数据确认成功！");
                                    this.loadData();
                                }
                            })
                        } else {
                            this.$Message.error("请选择批次号！");
                        }
                    }
                })
            },
            onSuccess() {
                this.$Message.success("上传成功！");
                this.loadData(1);
                this.getTacp0016List();
            }
        },
        created() {
            this.loadData();
            this.getTacp0016List();
            this.isCanDetermine();
        },
    }
</script>
<style scoped>
    .paging {
        float: right;
        margin-top: 10px;
    }

    /deep/ .ivu-upload-list {
        display: none;
    }

    /deep/ .ivu-table-cell {
        padding-right: 0px;
        padding-left: 0px;
    }

    /deep/ #area .ivu-col-span-8 {
        width: 50%;
    }

    #area :nth-child(3) {
        display: none;
    }
</style>
